package gang.org.springframework.framework.context;

import gang.org.springframework.framework.bean.GangBeanDefinition;
import gang.org.springframework.framework.core.io.GangResourcePatternResolver;
import gang.org.springframework.framework.factory.GangConfigurableListableBeanFactory;
import gang.org.springframework.framework.factory.GangDefaultListableBeanFactory;
import gang.org.springframework.framework.io.GangResource;
import gang.org.springframework.framework.io.GangResourceLoader;
import gang.org.springframework.framework.support.GangBeanDefinitionRegistry;
import gang.org.springframework.framework.web.context.support.GangServletContextResourcePatternResolver;

/**
 * @author gang.chen
 * @description
 * @Date 2021/6/13 22:21
 */
public class GangGenericApplicationContext extends GangAbstractApplicationContext implements GangBeanDefinitionRegistry {

    private final GangDefaultListableBeanFactory beanFactory;

    private GangResourceLoader resourceLoader;

    public GangGenericApplicationContext(){
        beanFactory = new GangDefaultListableBeanFactory();
    }

    @Override
    public void registerBeanDefinition(String beanName, GangBeanDefinition beanDefinition) {
        beanFactory.registerBeanDefinition(beanName,beanDefinition);
    }

    @Override
    public boolean containsBeanDefinition(String beanName) {
        return false;
    }

    @Override
    public GangBeanDefinition getBeanDefinition(String beanName) {
        return null;
    }


    @Override
    public GangConfigurableListableBeanFactory getBeanFactory()
    {
        return this.beanFactory;
    }

    @Override
    public Class<?> getType(String name) {
        return null;
    }

    @Override
    public Class<?> getType(String name, boolean allowFactoryBeanInit) {
        return null;
    }

    @Override
    public Object getBean(String name) {
        return null;
    }

    @Override
    public GangResource[] getResources(String locationPattern) {

        if (this.resourceLoader instanceof GangResourcePatternResolver) {
            //TODO
        }

        return super.getResources(locationPattern);
    }

    @Override
    protected GangResourcePatternResolver getResourcePatternResolver() {
        return new GangServletContextResourcePatternResolver(this);
    }

    @Override
    public String[] getBeanNamesForType(Class<?> type) {
        // TODO
        return new String[0];
    }
}
